<div class="box">
    <div class="heading">
        <h1><img alt="" src="<?php echo base_url('assets/admin/images/review.png'); ?>"> Posts</h1>
		<div class="buttons">
            <ul id="add_entry_btn">
                <li id="add_entry_li">
                    <a class="button" rel="#entry_content_types" id="add_entry" href="<?php echo base_url(ADMIN_PATH . '/posts/addpage'); ?>"><span>Add Post</span></a>
                </li>
                <li>
                    <a class="button delete" href="#"><span>Delete</span></a>
                </li>
            </ul>
        </div>  
    </div>
    <div class="content">
		<?php echo form_open(); ?>
        <div class="filter">
            <div class="left">
                <div><label>Search:</label></div> 
                <input type="text" name="filter[search]" value="<?php echo set_filter('posts', 'search'); ?>" /></td>
            </div>
            <div class="left">
                <div><label>Status:</label></div> 
                <?php echo form_dropdown('filter[status]', array(''=>'', 'published'=>'Published', 'draft'=>'Draft', 'disabled' => 'Disabled'), set_filter('entries', 'status')); ?></td>
            </div>
            <div class="left filter_buttons">
                <button name="submit" class="button" type="submit"><span>Filter</span></button>
                <button name="clear_filter" value="1" class="button" type="submit"><span>Clear</span></button>
            </div>
            <div class="clear"></div>
        </div>
        <?php echo form_close(); ?>
		<?php echo form_open(null, 'id="form"'); ?>
        <table id="entries_table" class="list">
            <thead>
                <tr>
                    <th width="1" class="center"><input type="checkbox" onClick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></th>
					<th class="right"><a rel="id" class="sortable" href="#">#ID</a></th>
                    <th><a rel="title" class="sortable" href="#">Title</a></th>
                    <th><a rel="slug" class="sortable" href="#">Slug</a></th>
					<th><a rel="author" class="sortable" href="#">Author</a></th>
					<th><a rel="comments" class="sortable" href="#">Total Comments</a></th>
                    <th><a rel="status" class="sortable" href="#">Status</a></th>
					<th><a rel="date_added" class="sortable" href="#">Date Added</a></th>
                    <th><a rel="date_modified" class="sortable" href="#">Last Modified</a></th>
                    <th class="right">Action</th>
                </tr>
            </thead>
            <tbody>
                <?php if ($posts){?>
                    <?php foreach($posts as $post){ ?>
                    <tr>
                        <td class="center"><input type="checkbox" value="<?php echo $post['postid'] ?>" name="selected[]" /></td>
						<td><?php echo $post['postid']; ?></td>
                        <td><?php echo stripslashes($post['title']); ?></td>
                        <td><?php echo $post['slug']; ?></td>
                        <td class="right"><?php echo $post['author']; ?></td>
                        <td class="right"><?php echo $post['comment_count']; ?></td>
                        <td><?php echo ucwords($post['status']); ?></td>
						<td><?php echo date('m/d/Y h:i a', strtotime($post['date_added'])); ?></td>
                        <td><?php echo date('m/d/Y h:i a', strtotime($post['date_modified'])); ?></td>
                        <td class="right"><?php if ($post['slug'] != ''){ ?>[ <?php echo anchor($post['slug'], 'View', 'target="_blank"'); ?> ]<?php } ?> [ <?php echo anchor(ADMIN_PATH . "/post/editpost/" . $post['postid'], 'Edit'); ?> ]</td>
                    </tr>
                    <?php } ?>
                <?php }else { ?>
                    <tr class="center"><td colspan="10">No results found.</td></tr>
                <?php } ?>
            </tbody>
        </table>
        <?php echo form_close(); ?>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $('.delete').click( function() {
            if (confirm('Delete cannot be undone! Are you sure you want to do this?'))
            {
                $('#form').attr('action', '<?php echo site_url(ADMIN_PATH . '/post/deletepost'); ?>').submit()
            }
            else
            {
                return false;
            }
        });
    });
</script>